package com.wdd.libbase.http

import android.content.Context
import com.bumptech.glide.Glide
import com.bumptech.glide.Registry
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader
import com.bumptech.glide.load.model.GlideUrl
import com.bumptech.glide.module.AppGlideModule
import com.wdd.libbase.di.annotation.GlideOkHttpClient
import com.wdd.libbase.di.component.DaggerGlideOkhttpComponent
import okhttp3.OkHttpClient
import java.io.InputStream
import javax.inject.Inject

/**
 *
 * @ProjectName:    OwnTool
 * @Package:        com.wdd.libbase.http
 * @ClassName:      OkHttpLibraryGlideModule
 * @Description:     java类作用描述
 * @Author:         王丹丹
 * @CreateDate:     2019/12/6 13:53
 * @UpdateUser:     更新者
 * @UpdateDate:     2019/12/6 13:53
 * @UpdateRemark:   更新说明
 * @Version:        1.0
 */
@GlideModule
class OkHttpLibraryGlideModule : AppGlideModule() {

    @GlideOkHttpClient
    @set:Inject
    internal var httpBuilder: OkHttpClient.Builder? = null

    init {
        DaggerGlideOkhttpComponent.create().inject(this)
    }


    override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
        registry.replace(
            GlideUrl::class.java, InputStream::class.java,
            OkHttpUrlLoader.Factory(httpBuilder!!.build())

        )
    }
}